{{define "admin.add"}}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>管理员添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/statics/third-pkg/layui/css/layui.css">
    <link rel="stylesheet" href="/statics/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" lay-verify="required|username" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
                <tip>填写自己管理账号的名称。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">手机</label>
            <div class="layui-input-block">
                <input type="number" name="phone" lay-verify="required|phone" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">邮箱</label>
            <div class="layui-input-block">
                <input type="email" name="email" lay-verify="required|email" lay-reqtext="邮箱号不能为空" placeholder="请输入邮箱" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label required">密码</label>
            <div class="layui-input-block ">
                <input type="password" name="password" lay-verify="required|pass" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">角色</label>
            <div class="layui-input-block">
                <div id="roles" class="xm-select"></div>
            </div>
        </div>
        <div class="layui-form-item" id="area-picker">
            <div class="layui-form-label">所在地区</div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="province" class="province-selector" lay-verify="required" data-value="广东省" lay-filter="province-1">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="city" class="city-selector"   lay-verify="required" data-value="深圳市" lay-filter="city-1">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="county" class="county-selector"   lay-verify="required" data-value="龙岗区" lay-filter="county-1">
                    <option value="">请选择区</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label required">详细地址</label>
            <div class="layui-input-block ">
                <input type="text" name="address" lay-verify="required"  lay-reqtext="地址" placeholder="请输入地址" value="{{ .model.Address }}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <!--</div>-->
    <script src="/statics/third-pkg/layui/layui.js"></script>
    <script src="/statics/admin/js/lay-config.js?v=2.0" charset="utf-8"></script>

    <script>

        layui.use(['form','request','layer','miniTab','common',"layarea","xmSelect"], function() {
            var form = layui.form,
                layer = layui.layer,
                miniTab = layui.miniTab,
                common=layui.common,
                layarea = layui.layarea,
                request=layui.request;
            layarea.render({
                elem: '#area-picker',
                change: function (res) {

                }
            });

            var role = xmSelect.render({
                el: '#roles',
                radio: true,
                name: 'role',
                layVerify: 'required',
                layVerType: 'msg',
                filterable: true,
                height: 'auto',
                clickClose:true,
                paging: true,
                // pageEmptyShow: false,
                //远程分页
                pageRemote: true,
                theme: {
                    color: '#0081ff',
                },
                data: [
                ],
                remoteMethod: function(val, cb, show, pageIndex){
                    //val: 搜索框的内容, 不开启搜索默认为空, cb: 回调函数, show: 当前下拉框是否展开, pageIndex: 当前第几页
                    request.get('admin/roles/select-get-list?limit=10&page='+pageIndex).then(function (response) {
                        if (response.data.code == 0) {
                            //这里是success的处理
                            var res = response.data;
                            //回调需要两个参数, 第一个: 数据数组, 第二个: 总页码
                            cb(res.data,response.data.pagination.page_count)
                        } else {
                            layer.msg(response.data.msg);
                            cb([], 0);
                        }
                    }).catch(function (error) {
                        //这里是error的处理
                        cb([], 0);
                        layer.msg('获取角色失败');
                    })
                }
            })


            form.verify({
                username: function(value, item){ //value：表单的值、item：表单的DOM对象
                    if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
                        return '用户名不能有特殊字符';
                    }
                    if(/(^\_)|(\__)|(\_+$)/.test(value)){
                        return '用户名首尾不能出现下划线\'_\'';
                    }
                    if(/^\d+\d+\d$/.test(value)){
                        return '用户名不能全为数字';
                    }

                    //如果不想自动弹出默认提示框，可以直接返回 true，这时你可以通过其他任意方式提示（v2.5.7 新增）
                    if(value === 'xxx'){
                        layer.msg('用户名不能为敏感词')
                        return true;
                    }
                }
                ,pass: [
                    /^[\S]{6,12}$/
                    ,'密码必须6到12位，且不能出现空格'
                ]
            });
            //监听提交
            form.on('submit(saveBtn)', function(data) {
                data.field['address']=data.field['address']
                request.post('admin/admin/add',data.field).then(function (response) {
                    if(response.data.code==0){
                        layer.msg('添加用户成功',{
                            time:1000
                        },function (){
                            localStorage.setItem("admin-add",common.generateUUID())
                            miniTab.deleteCurrentByIframe();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);

                            window.location.href="/admin/admin/list";
                        })
                    }else{
                        layer.msg(response.data.msg);
                    }
                }).catch(function (error) {
                    console.log(error)
                    layer.msg('提交失败');
                });

            });

        });
    </script>
</body>

</html>
{{ end }}